package com.gly091020.ohMyPC.mixin;

import com.gly091020.ohMyPC.SoundLoader;
import net.minecraft.CrashReport;
import net.minecraft.ReportType;
import net.neoforged.fml.ModList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.nio.file.Path;

@Mixin(CrashReport.class)
public class CrashMixin {
    @Inject(method = "saveToFile(Ljava/nio/file/Path;Lnet/minecraft/ReportType;)Z", at = @At("HEAD"))
    private static void playOhMyPC(Path path, ReportType type, CallbackInfoReturnable<Boolean> cir){
        SoundLoader.init();
        SoundLoader.tryPlay();
        try {
            if(ModList.get().isLoaded("notenoughcrashes")){
                return;
            }
            Thread.sleep(3000);
        } catch (Exception ignored) {}
    }
}
